import Vue from "vue";
import { Sku } from "vant";
import VueRouter from "vue-router";
import shouYe from "../views/shouYe.vue";
import dingDan from "../views/dingDan.vue";
import Cart from "../views/Cart.vue";
import Me from "../views/Me.vue";
import Zhuce from "../views/zhuce.vue";
import Login from "../views/login.vue";
import weiDeng from "../views/weidenglu/weiDeng.vue";
import Index from "../views/index.vue";
import QianBao from "../views/me/qianbao.vue";
import ChongZeng from "../views/me/chongzeng.vue";
import QingKe from "../views/me/qingke.vue";
import ZhuanZeng from "../views/me/zhuanzeng.vue";
import HongBao from "../views/me/hongbao.vue";
import ShiBai from "../views/shop/shibai.vue";
import Juan from "../views/me/juan.vue";
import DuiHuan from "../views/me/duihuan.vue";
import FaPiao from "../views/me/fapiao.vue";
import Detail from "../views/detail.vue";
import Guodu from '../views/guodu.vue'
import Order from '../views/order.vue'
import DiZhi from '../views/dizhi.vue'
import Edit from '../views/edit.vue'
import ChengGong from '../views/shop/chenggong.vue'
import Mima from '../views/mima.vue'
import orderDetail from '../views/orderdetail.vue'



Vue.use(VueRouter);
Vue.use(Sku);

const routes = [
  {
    path: "/",
    name: "Index",
    redirect: "/gt",
    component: Index,
    children: [
      {
        path: "/s",
        name: "shouYe",
        component: shouYe
      },
      {
        path: "/c",
        name: "caiDan",
        component: () =>
          import(/* webpackChunkName: "about" */ "../views/caiDan.vue")
      },
      {
        path: "/d",
        name: "dingDan",
        component: dingDan,
        meta: {
          isLogin: true
        }
      },
      {
        path: "/t",
        name: "Cart",
        component: Cart,
        meta: {
          isLogin: true
        }
      },
      {
        path: "/m",
        name: "Me",
        component: Me
      },
      {
        path: "/w",
        name: "Wei",
        component: weiDeng
      }
    ]
  },
  {
    path: "/z",
    name: "Zhuce",
    component: Zhuce
  },
  {
    path: "/l",
    name: "Login",
    component: Login
  },
  {
    path: "/q",
    name: "QianBao",
    component: QianBao
  },
  {
    path: "/ch",
    name: "ChongZeng",
    component: ChongZeng
  },
  {
    path: "/qk",
    name: "QingKe",
    component: QingKe
  },
  {
    path: "/zz",
    name: "ZhuanZeng",
    component: ZhuanZeng
  },
  {
    path: "/hb",
    name: "HongBao",
    component: HongBao
  },
  {
    path: "/sb",
    name: "ShiBai",
    component: ShiBai
  },
  {
    path: "/j",
    name: "Juan",
    component: Juan
  },
  {
    path: "/dh",
    name: "DuiHuan",
    component: DuiHuan
  },
  {
    path: "/fp",
    name: "FaPiao",
    component: FaPiao
  },
  {
    path: "/dt",
    name: "Detail",
    component: Detail
  },
  {
    path: "/gt",
    name: "Guodu",
    component: Guodu
  },
  {
    path: "/o",
    name: "Order",
    component: Order
  },
  {
    path: "/dz",
    name: "DiZhi",
    component: DiZhi
  },
  {
    path: "/ed",
    name: "Edit",
    component: Edit
  },
  {
    path: "/cg",
    name: "ChengGong",
    component: ChengGong
  },
  {
    path: "/mi",
    name: "Mima",
    component: Mima
  },
  {
    path: "/order",
    name: "orderDetail",
    component: orderDetail
  }
];

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  if (to.meta.isLogin) {
    if (localStorage.getItem("token")) {
      next();
    } else {
      next({
        name: "Login"
      });
    }
  } else {
    next();
  }
});

export default router;
